<template>
<div>
  {{resp}}
</div>
</template>

<script>
  export default {
    name: "TestVueResource",
    data() {
      return {
        resp: 'this is a test!!!'
      }
    },
    created() {

    },
    mounted() {
      this.doGet('https://www.fastmock.site/mock/5eae0d42eb20a2d3b118434f40301d71/mock/test123');


      this.doPost('https://www.fastmock.site/mock/5eae0d42eb20a2d3b118434f40301d71/mock/testpost')
    },
    destroyed() {
    },
    methods: {
      doGet(url){
        //无参数get请求
        this.$http.get(url).then(res =>{
          console.log('接口'+url+'请求结果'+JSON.stringify(res));

          if (res.status === 200 ){
            this.resp = res.body.wasd;
          }



        }).catch(catchRes => {
          console.log('接口'+url+'异常返回'+JSON.stringify(catchRes));
        });

      },


      doPost(url){
        this.$http.post(url).then(res =>{
          console.log('post-res: '+JSON.stringify(res))

        }).catch(cres =>{
          console.log('post-cres: '+JSON.stringify(cres))
        })
      }




    },
    computed: {},
    watch: {},

  }
</script>

<style scoped>

</style>
